package mume.music;

import java.io.IOException;
import java.util.Vector;

import android.content.Context;
import android.media.MediaPlayer;

public class Mp3Player {
	
	private Vector<String> playList;
	private MediaPlayer mp;
	boolean playing;
	
	public Mp3Player(Context parent){
		playList = new Vector<String>();
		mp = new MediaPlayer();
		playing = false;
	}
	
	public void setPlayList(Vector<String> songList){
		this.playList = songList;
	}
	
	public void playSong(int id){
		
		if(playList.size() > id)
		{
		    try {
		    	if(playing)
		    		stopSong();
				mp = new MediaPlayer();
		    	mp.setDataSource(playList.elementAt(id));
				mp.prepare();
			    mp.start();
			    playing = true;
		    } catch (IllegalArgumentException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IllegalStateException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} 
		}
	}
	
	public void togglePause(){
		mp.pause();
	}
	
	public void clearPlayList(){
		playList.clear();
	}
	public void stopSong(){
		mp.stop();
		playing = false;
	}
	
	
}
